#include "Common.h"
//==================================================
NODE *g_BeeHead;
NODE *g_BeeEnd;
//==================================================
int g_BeeSize = 16;
int g_BeeCount;
//==================================================
char g_BeeIconDown[3][3]={
	{' ','W',' '},
	{'O','X','O'},
	{' ','V',' '}};
char g_BeeIconUp[3][3]={
	{' ','A',' '},
	{'O','X','O'},
	{'I','M','I'}};
char g_BeeIconLeft[3][3]={
	{' ','O','='},
	{'X','X','='},
	{' ','O','='}};
char g_BeeIconRight[3][3]={
	{'=','O',' '},
	{'=','X','X'},
	{'=','O',' '}};
//==================================================
int g_BeeColor[5][3]={	{0x0040ff, 0x000000, 0x0040ff},
						{0x0000ff, 0xff0000, 0x0000ff},
						{0xff0000, 0x00ff00, 0xff0000},
						{0x0040ff, 0x000000, 0x0040ff},
						{0x0000ff, 0xff0000, 0x0000ff}};
//==================================================
VOID CALLBACK BeeTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
	if(g_Pause || 0==g_Time || g_Die)
	{
		return;
	}

	BeeDelete();
	BeeMove();
	InvalidateRect(hWnd, NULL, false);
}
//==================================================
void BeeCreate(char (*pIcon)[3])
{
	ListCreate(&g_BeeHead, &g_BeeEnd, pIcon);

	g_BeeEnd->nLX=0;
	g_BeeEnd->nLY=0;

	if(DIR_NULL == g_BeeEnd->nDir)
	{
		g_BeeEnd->nDir = DIR_DOWN;
	}
}
//==================================================
void BeeClear()
{
	ListClear(&g_BeeHead, &g_BeeEnd);
}
//==================================================
void BeeDelete()
{
	NODE *pTemp = g_BeeHead;

	while(NULL != pTemp)
	{
		if(1280 == pTemp->nY)
		{
			NodeDelete(&g_BeeHead, &g_BeeEnd, pTemp);
		}

		pTemp=pTemp->pNext;
	}

	BeeSum();
}
//==================================================
void BeeSum()
{
	g_BeeCount = 0;

	NODE *pTemp = g_BeeHead;

	while(NULL != pTemp)
	{
		g_BeeCount++;
		pTemp=pTemp->pNext;
	}
}
//==================================================
void BeeDraw(HDC hdc)
{
	SetTextAlign(hdc, TA_LEFT | VTA_TOP);
	NODE *pTemp = g_BeeHead;

	while(NULL != pTemp)
	{
		int i = 0;

		while(i<3)
		{
			RECT rl = {pTemp->nLX,pTemp->nLY+i*16,pTemp->nLX+48,pTemp->nLY+16+i*16};
			SetTextColor(hdc, 0xffffff);
			DrawText(hdc, pTemp->LText[i], 3, &rl, DT_CENTER);
			i++;
		}

		i = 0;

		while(i<3 && pTemp->nY < 1280)
		{
			RECT rt = {pTemp->nX,pTemp->nY+i*16,pTemp->nX+48,pTemp->nY+16+i*16};
			SetTextColor(hdc, g_BeeColor[(pTemp->nY + pTemp->nX)/48%5][i]);
			DrawText(hdc, pTemp->Text[i], 3, &rt, DT_CENTER);
			i++;
		}

		if(pTemp->nY >= 1280)
		{
			pTemp->nLX = 64;
			pTemp->nLY = 1280;
		}

		pTemp=pTemp->pNext;
	}
}
//==================================================
void BeeMove()
{
	NODE *pTemp = g_BeeHead;

	while(NULL != pTemp)
	{
		if(DIR_LEFT == pTemp->nDir)
		{
			SaveLastStatus(pTemp);
			pTemp->nX = pTemp->nX - g_BeeSize;
			if(pTemp->nX < 0)
			{
				pTemp->nDir = DIR_RIGHT;
				NodeTextModify(pTemp, g_BeeIconRight);
			}
		}
		else if(DIR_RIGHT == pTemp->nDir)
		{
			SaveLastStatus(pTemp);
			pTemp->nX = pTemp->nX + g_BeeSize;
			if(pTemp->nX > 1056 - g_BeeSize*3)
			{
				pTemp->nDir = DIR_LEFT;
				NodeTextModify(pTemp, g_BeeIconLeft);
			}
		}
		else if(DIR_UP == pTemp->nDir)
		{
			SaveLastStatus(pTemp);
			pTemp->nY = pTemp->nY - g_BeeSize;
			if(pTemp->nY <= 0)
			{
				pTemp->nDir = DIR_DOWN;
				NodeTextModify(pTemp, g_BeeIconDown);
			}
		}
		else if(DIR_DOWN == pTemp->nDir)
		{
			SaveLastStatus(pTemp);
			pTemp->nY = pTemp->nY + g_BeeSize;
			if(pTemp->nY > 480 - 128)
			{
				pTemp->nDir = DIR_UP;
				NodeTextModify(pTemp, g_BeeIconUp);
			}
		}

		pTemp=pTemp->pNext;
	}
}
